package com.example.xitong;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.gyf.immersionbar.ImmersionBar;



public class MainActivity extends AppCompatActivity {

    Shouye SY=new Shouye();
    Zs ZS=new Zs();
    Wd WD=new Wd();
    Nwwd NWWD=new Nwwd();
//    BottomNavigationView bottomNavigationView;
private TextView mTextMessage;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.item_bottomnav_home:
                    //首页
                    getSupportFragmentManager().beginTransaction().show(SY).hide(WD).hide(NWWD).hide(ZS).commit();

                    return true;
                case R.id.item_bottomnav_message:
                   // 跳转到学习
                    getSupportFragmentManager().beginTransaction().show(ZS).hide(WD).hide(NWWD).hide(SY).commit();
                    return true;
                case R.id.item_bottomnav_addressbook:
                   // 跳转到你问我答
                    getSupportFragmentManager().beginTransaction().show(NWWD).hide(ZS).hide(WD).hide(SY).commit();
                    return true;
                case R.id.item_bottomnav_wd:
                    //跳转到我的
                    getSupportFragmentManager().beginTransaction().show(WD).hide(ZS).hide(NWWD).hide(SY).commit();

                    return true;
            }
            return false;
        }
    };



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImmersionBar.with(this)
                //.statusBarColor(R.color.purple_200)
                .init();

        BottomNavigationView navigation = findViewById(R.id.bottomNavigationView_main);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        getSupportFragmentManager().beginTransaction().add(R.id.fragment,WD).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment,SY).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment,ZS).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment,NWWD).commit();


        //定义初始为首页
        getSupportFragmentManager().beginTransaction().show(SY).hide(WD).hide(NWWD).hide(ZS).commit();
//
//        bottomNavigationView=findViewById(R.id.bottomNavigationView_main);
//        bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
//            @Override
//            public void onNavigationItemReselected(@NonNull MenuItem item) {
//
//                switch (item.getItemId()){
//                    case R.id.item_bottomnav_home:
//                        getSupportFragmentManager().beginTransaction().show(SY).hide(WD).hide(NWWD).hide(ZS).commit();
//                        break;
//                    case R.id.item_bottomnav_message:
//                        getSupportFragmentManager().beginTransaction().show(ZS).hide(WD).hide(NWWD).hide(SY).commit();
//                        break;
//                    case R.id.item_bottomnav_addressbook:
//                        getSupportFragmentManager().beginTransaction().show(NWWD).hide(ZS).hide(WD).hide(SY).commit();
//                        break;
//                    case R.id.item_bottomnav_wd:
//                        getSupportFragmentManager().beginTransaction().show(WD).hide(ZS).hide(NWWD).hide(SY).commit();
//                        break;
//                }
//
//            }
//        });





    }
}